package com.example.icongyou;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_main);
        // 处理系统栏间距（保持原有代码）
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });

        // 初始化所有点击事件（包括学生端和教师端）
        setupClickListeners();
    }

    private void setupClickListeners() {
        // 教师端卡片点击事件（保持原有逻辑）
        View teacherLoginCard = findViewById(R.id.teacher_login_card);
        if (teacherLoginCard != null) {
            teacherLoginCard.setOnClickListener(v -> navigateToTeacherPage());
        }

        // 新增：学生端卡片点击事件
        View studentLoginCard = findViewById(R.id.student_login_card);
        if (studentLoginCard != null) {
            studentLoginCard.setOnClickListener(v -> navigateToStudentMainActivity());
        } else {
            Toast.makeText(this, "未找到student_login_card控件", Toast.LENGTH_SHORT).show();
        }
    }

    private void navigateToTeacherPage() {
        try {
            // 创建跳转意图
            Intent intent = new Intent(MainActivity.this, LoginActivity.class);
            startActivity(intent);
            // 可选：添加跳转动画
            //overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
        } catch (Exception e) {
            Toast.makeText(this, "教师端跳转失败: " + e.getMessage(), Toast.LENGTH_SHORT).show();
            e.printStackTrace();
        }
    }
    private void navigateToStudentMainActivity() {
        try {
            // 先跳转到登录页面，而不是直接进入学生主页面
            Intent intent = new Intent(MainActivity.this, LoginActivity.class);
            startActivity(intent);
            overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left);
        } catch (Exception e) {
            Toast.makeText(this, "跳转登录页面失败: " + e.getMessage(), Toast.LENGTH_SHORT).show();
            e.printStackTrace();
        }
    }
}